import java.util.ArrayList;
/**
 * This class let the user create and edit a planning of the performances he want to see
 * 
 * @author Mathieu Reymond & Jonathan Smet 
 * @version 03/05/11
 */
public class Planning
{
    private ArrayList<String> planningList = new ArrayList<String>();    

    /**
     * Makes a new planning
     */
    public Planning()
    {
    }
    
    /**
     * Add a performance to your planning
     * 
     * @param performanceName The name of the performance the user adds to his planning
     */
    public void addPerformance(String performanceName)
    {
        if(!planningList.contains(performanceName))
        {
            planningList.add(performanceName);
        }
    }
    
    /**
     * Check if the performance's showtime overlaps the time of other performances
     * 
     * @param performanceName The name of the performance to check
     * 
     * @return The list of all the performances that are overlapped
     */
    public ArrayList<String> checkFree(String performanceName)
    {
        ArrayList<String> notFree = new ArrayList<String>();
        long startCheck = LineUp.getLineUp().get(performanceName).getStartDate().getTime();
        long stopCheck = LineUp.getLineUp().get(performanceName).getStopDate().getTime();
        long startToCheck;
        long stopToCheck;
        
        if(!planningList.isEmpty())
        {
            for(int index = 0; index < planningList.size(); index++)
            {   
                startToCheck = LineUp.getLineUp().get(planningList.get(index)).getStartDate().getTime();
                stopToCheck = LineUp.getLineUp().get(planningList.get(index)).getStopDate().getTime();
                if( (startCheck > startToCheck && startCheck < stopToCheck) || (stopCheck > startToCheck && stopCheck < stopToCheck) )
                {
                    notFree.add(planningList.get(index));
                }
            }
        }
        return notFree;
    }
    
    /**
     * Remove the performance of the planning's list
     * 
     * @param performanceName The name of the performance that is going to be removed
     */
    public void removePerformance(String performanceName)
    {
        planningList.remove(performanceName);
    }
    
        /**
     * Returns the list of the names of the performances that are planned by a user.
     * 
     * @return The list of the plannend performances
     */
    public ArrayList<String> getPlanningList()
    {
        return planningList;
    }
}
